/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Raytracing.BRDF;

import Raytracing.Ray;
import Raytracing.Shaders.TextureProvider;
import processing.core.PVector;

/**
 *
 * @author Matt
 */
public class BlendBRDF implements BRDF{

    BRDF a;
    BRDF b;
    TextureProvider blend;
    
    public BlendBRDF(BRDF a, BRDF b, TextureProvider blend){
        
        this.a = a;
        this.b = b;
        this.blend = blend;
        
        
    }
    
    
    public PVector getReflectance(PVector incoming, PVector outgoing, PVector normal, float tu, float tv, PVector u, PVector v) {
        
        //check the UV coords and figure out which one to do
        PVector amount = new PVector();
        blend.getColor(tu, tv, amount);
        
        if (Math.random() < amount.x){       
            return a.getReflectance(incoming, outgoing, normal, tu, tv, u, v);
        }
        else{
            return b.getReflectance(incoming, outgoing, normal, tu, tv, u, v); 
        }
        
    
    
    }

    public float sampleReflectance(PVector outgoing, Ray sample, PVector normal, PVector BRDF, float tu, float tv, PVector u, PVector v, float u1, float u2) {
        //check the UV coords and figure out which one to do
        PVector amount = new PVector();
        blend.getColor(tu, tv, amount);
        
        if (Math.random() < amount.x){       
            return a.sampleReflectance(outgoing, sample, normal, BRDF, tu, tv, u, v, u1, u2);
        }
        else{
            return b.sampleReflectance(outgoing, sample, normal, BRDF, tu, tv, u, v, u1, u2);
        }
    }
    
    
    
    
    
}
